<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var departmentUserDataGrid;
    var departmentId=null;
    $(function() {
    	departmentId='${departmentId}';
        departmentUserDataGrid = $('#departmentUserDataGrid').datagrid({
            url : '${path }/admin/department/getDepartmentUserList?departmentId='+departmentId,
            fit : true,
            striped : true,
            rownumbers : true,
            pagination : true,
            idField : 'id',
	        sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20],
            columns : [ [{
                width : '80',
                title : '登录名',
                field : 'login_name',
                sortable : true
            }, {
                width : '80',
                title : '姓名',
                field : 'name',
                sortable : true
            },{
                width : '40',
                title : '性别',
                field : 'sex',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                    case 0:
                        return '男';
                    case 1:
                        return '女';
                    }
                }
            },{
                width : '120',
                title : '电话',
                field : 'phone',
                sortable : true
            },{
                width : '120',
                title : '邮箱',
                field : 'email',
                sortable : true
            },{
                width : '60',
                title : '状态',
                field : 'status',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                    case 0:
                        return '正常';
                    case 1:
                        return '停用';
                    }
                }
            } 
             , {
                field : 'action',
                title : '操作',
                width : 80,
                formatter : function(value, row, index) {
                    var str = '';
                        <shiro:hasPermission name="/admin/department/removeAssignUser">
                            str += $.formatString('<a href="javascript:void(0)" class="user-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="removeAssignUser(\'{0}\');" >删除</a>', row.id);
                        </shiro:hasPermission>
                    return str;
                }
            } 
            ] ],
            onLoadSuccess:function(data){
                $('.user-easyui-linkbutton-del').linkbutton({text:'删除'});
            }
        });
    });
    
   function removeAssignUser(id) {
     if (id == undefined) {
        	var rows = departmentUserDataGrid.datagrid('getSelections');
        	id = rows[0].id;
        } else {
            departmentUserDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除当前信息？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path }/admin/department/removeAssignUser', {
                    departmentId:departmentId,
                    userId:id
                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        departmentUserDataGrid.datagrid('reload');
                    } else {
                        parent.$.messager.alert('错误', result.msg, 'error');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:true,title:'管理账户列表'" >
        <table id="departmentUserDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
